<?php
require_once 'log/Logger.php';
$account = $_POST["account"];
$rolename = $_POST["rolename"];
$state = $_POST["state"];
$mapid = $_POST["mapid"];
$money = $_POST["money"];
$itemcount = $_POST["itemcount"];
$position = $_POST["position"];
$killmoncount = $_POST["killmoncount"];
$skillbuf = $_POST["skillbuf"];
$level = $_POST["level"];
$fatigue = $_POST["fatigue"];
$job = $_POST["job"];


$conn = mysql_connect('ltfll.gicp.net','qqxj','qqxj');
if(!$conn)
{
    Logger::getLogger()->debug('connect fail!'.mysql_error());
    echo "connect fail!".mysql_error()."\n";
}
mysql_select_db('botlog',$conn);

$day = date("Ymd");
$sql = "insert into {$day}_botlog (account,rolename,state,mapid,money,last_refresh_time,itemcount,position,killmoncount,skillbuf,level,fatigue,job) values ";
$sql = $sql."('{$account}','{$rolename}','{$state}','{$mapid}','{$money}',now(),'{$itemcount}','{$position}','{$killmoncount}','{$skillbuf}','{$level}','{$fatigue}','{$job}')";


$createtablesql =  "CREATE TABLE IF NOT EXISTS`{$day}_botlog` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
  `account` varchar(45) DEFAULT NULL,
  `rolename` varchar(45) DEFAULT NULL,
  `state` varchar(45) DEFAULT NULL,
  `mapid` varchar(45) DEFAULT NULL,
  `money` int(11) DEFAULT NULL,
  `last_refresh_time` datetime DEFAULT NULL,
  `itemcount` int(11) DEFAULT NULL,
  `position` varchar(45) DEFAULT NULL,
  `killmoncount` int(11) DEFAULT NULL,
  `skillbuf` varchar(45) DEFAULT NULL,
  `level` int(11) DEFAULT NULL,
  `fatigue` int(11) DEFAULT NULL,
  `job` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=gbk";
$rs = mysql_query($createtablesql, $conn);

mysql_query("SET NAMES 'GBK'");
$rs = mysql_query($sql, $conn);

if($rs)
{
    Logger::getLogger()->debug("insert ok\n");
    Logger::getLogger()->debug($sql."\n");
    echo "inser ok\n";
}
else
{
    Logger::getLogger()->debug('insert fail!'.mysql_error()."\n");
    Logger::getLogger()->debug($sql."\n");
    echo "insert fail!".mysql_error()."\n";
}